package edu.hhu.innerac.sparkm.demo;

import java.util.ArrayList;
import java.util.List;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;

import edu.hhu.innerac.sparkm.entry.Rectangle;

public class CalcuArea {
	public static void main(String args[]){
//		System.setProperty("hadoop.home.dir", "F:/hadoop-common-2.2.0-bin-master");
//    	SparkConf sparkConf = new SparkConf().setAppName("JavaSparkPi").setMaster("spark://master:7077");
    	SparkConf sparkConf = new SparkConf().setAppName("JavaSparkPi").setMaster("local");
    	JavaSparkContext jsc = new JavaSparkContext(sparkConf);
    	
    	List<Rectangle> nums = new ArrayList<Rectangle>();
    	nums.add(new Rectangle(2, 4));
    	nums.add(new Rectangle(3, 6));
    	nums.add(new Rectangle(4, 8));
    	nums.add(new Rectangle(5, 10));
    	nums.add(new Rectangle(6, 12));
    	
    	JavaRDD<Rectangle> numdds = jsc.parallelize(nums);
    	
    	System.out.println(numdds.count());
    	JavaRDD<String> numddes = numdds.map(new Function<Rectangle, String>() {

			public String call(Rectangle v1) throws Exception {
				v1.setArea(v1.getHeight() * v1.getWidth());
				return v1.toString();
			}
		});
    	System.out.println(numddes.collect());
    	jsc.stop();
	}
}
